package com.trailer.lookimg.fragment

import android.os.Bundle
import android.util.Log
import android.view.LayoutInflater
import android.view.ViewGroup
import com.bumptech.glide.Glide
import com.bumptech.glide.load.engine.DiskCacheStrategy
import com.bumptech.glide.request.RequestOptions
import com.github.chrisbanes.photoview.PhotoViewAttacher
import com.trailer.lookimg.vmodel.ImageDetailVModel
import com.trailer.base.base.BFragment
import com.trailer.base.inter.IUser
import com.trailer.lookimg.R
import com.trailer.lookimg.databinding.FragmentImagedetailBinding

/**
 *
 *on 2020/9/18
 */
class ImageDetailFragment : BFragment<ImageDetailVModel, FragmentImagedetailBinding>(){

    var url=""
    override fun __before(savedInstanceState: Bundle?) {
        super.__before(savedInstanceState)
        url = arguments?.getString("url")!!
    }


    override fun init(savedInstanceState: Bundle?) {
        super.init(savedInstanceState)
        Log.e("-shy-", "url=: $url")
        vm.url.value=url

        Glide.with(this)
            .load(url)
            .apply(getTwo())
            .into(binding.image)
        initImg()
    }

    fun getTwo(): RequestOptions {

        return RequestOptions()
            .diskCacheStrategy(DiskCacheStrategy.ALL)
            .placeholder(R.drawable.bg_need_error)
            .error(R.drawable.bg_need_error)
            .skipMemoryCache(true)
    }

    private fun initImg(){

        var mAttacher= PhotoViewAttacher(binding.image)

//        mAttacher.setOnPhotoTapListener{
//            view, x, y ->
//            (context as Activity).onBackPressed()
//        }

    }



    override fun binding(inflater: LayoutInflater, container: ViewGroup?): FragmentImagedetailBinding {
       return FragmentImagedetailBinding.inflate(inflater)
    }

    override fun vmClass(): Class<ImageDetailVModel> {
        return ImageDetailVModel::class.java
    }


    override fun user(): IUser? {
        TODO("Not yet implemented")
    }
}
